<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('优惠卷信息列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <input id="couponId" th:value="${couponId}" type="hidden">
            <input type="text" class="form-control mr-1" name="userName" placeholder="请输入持有人...">
            <input type="text" class="form-control mr-1" name="couponCode" placeholder="请输入优惠卷编码...">
            <select name="status" class="form-control mr-1" th:with="type=${@dict.getType('qdx_coupon_status')}">
                <option value="">状态</option>
                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
            </select>
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i>
                搜索
            </button>
            <button type="button" class="btn btn-default" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>
                重置
            </button>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('dal:couponCode:edit')}]];
    var removeFlag = [[${@permission.hasPermi('dal:couponCode:remove')}]];
    var sta = [[${@dict.getType('qdx_coupon_status')}]];
    var prefix = "/coupon/code";
    var couponId = $("#couponId").val();
    $(function() {
        var options = {
            url: prefix + "/list.json?couponId=" + couponId,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            modalName: "优惠卷信息",
            columns: [
                {
                    field: 'id',
                    title: 'id'
                },
                {
                    field: 'couponCode',
                    title: '优惠卷编码'
                },
                {
                    field: 'userName',
                    title: '持有人',
                    formatter: function (value, row, index) {
                        if (row.userId > 0) {
                            return row.userName + " <span style='color: #DD1144'>(id:" + row.userId + ")</span>";
                        } else {
                            return "-";
                        }

                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(sta, value);
                    }
                },
                {
                    field: 'payTime',
                    title: '使用时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.status === 1) {
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="RecoveryOrWaste(\'' + row.id + '\',\'' + 4 + '\')"><i class="fa fa-remove"></i>作废</a> ');
                        } else if (row.status === 4) {
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="RecoveryOrWaste(\'' + row.id + '\',\'' + 1 + '\')"><i class="fa fa-mail-reply-all"></i>恢复</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //作废或恢复
    function RecoveryOrWaste(id,sta) {
        table.set();
        var str = "";
        if (sta == 4) {
            str = "确定执行作废优惠券"
        } else {
            str = "确定执行恢复优惠券"
        }
        $.modal.confirm(str, function () {
            var data = {"id": id, "status": sta};
            $.operate.submit(prefix + "/status.json", "post", "json", data);
        });
    }
</script>
</body>
</html>